<?php
header("Content-Type:application/json;charset=utf-8");
//header('Access-Control-Allow-Origin:*');

if($_SERVER["REQUEST_METHOD"]=="POST"){
    if(isset($_POST["uname"])&&isset($_POST["upwd"])){
        $UNAME=$_POST["uname"];
        $UPWD=$_POST["upwd"];
        $UTEL=$_POST["utel"];
        //1.准备链接参数
        $host="127.0.0.1";
        $name="root";
        $pwd="";
        $db="mia";
        $port="3306";
        //2.创建数据库链接
        $conn=new mysqli($host,$name,$pwd,$db,$port);
        //3.设置连接字符集
        mysqli_query($conn,"set names utf8");
        //4.准备sql
        $sql="INSERT INTO `userinfo`(`uname`,`upwd`,`utel`) VALUES('".$UNAME."','".$UPWD."','".$UTEL."');";
        //5.执行 sql,并得到结果
        $result=$conn->query($sql);
        //6.判断结果
        if($result==1){
            $arr=array("msg"=>"注册成功","status"=>1);
            print_r(json_encode($arr));
        }else{
            $arr=array("msg"=>"注册失败","status"=>0);
            print_r(json_encode($arr));
        }
        //关闭链接
        $conn->close();
    }
}else{
    $arr=array("msg"=>"不支持get请求","status"=>-1);
    print_r(json_encode($arr));
}